package com.demo.wrapper.interfaces;

import com.demo.wrapper.function.IGetter;
import com.demo.wrapper.utils.LambdaUtil;

import java.util.Objects;

/**
 * lambda表达式基础接口
 *
 * @param <Wrapper> 条件拼接类
 * @param <DO>      文档实体类
 * @author 19242
 */
public interface ILambdaWrapper<Wrapper extends ILambdaWrapper<Wrapper, DO>, DO> extends IBaseWrapper<Wrapper> {

    /**
     * 根据get方法获取字段名
     *
     * @param getter
     * @return
     */
    default String findField(IGetter<DO> getter) {
        return LambdaUtil.getClassPropertiesName(getter);
    }

    /**
     * 根据get方法获取字段名
     *
     * @param getters
     * @return
     */
    default String[] findFields(IGetter<DO>[] getters) {
        if (Objects.isNull(getters)) {
            return null;
        }
        String[] fields = new String[getters.length];
        for (int i = 0; i < getters.length; i++) {
            fields[i] = findField(getters[i]);
        }
        return fields;
    }
}
